<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-1-31
 * Time: 下午1:34
 */
require ('core/shop.php');
quanli_include('module/base/common/quanliOnlinepay.class.php');


//实例支付类
$ebsigOnlinepay = new quanliOnlinepay();




$params = $_REQUEST;
$package = file_get_contents('php://input');



if($params['trade_state'] == 0 && $params['partner'] == '1219005701' && isset($params['out_trade_no']))
{
    $bill_no = $params['out_trade_no'];
    //查询订单信息
    $bill_array =& $G_SHOP->DBCA->stmt_query('SELECT * FROM bill_master WHERE bill_no = ?', 's', $bill_no);
    if (!$bill_array) {
        error_log(print_r($bill_array,1));
        die( 'fail' );
    }

    $pcustID = $bill_array[0]->pcustID;
    $payTypeID = 63;//$bill_array[0]->payTypeID;

    //查询订单支付,若是撒娇订单则添加一条数据 add by Jerry 2015-04-26
    $bill_pay_obj =  new entity('bill_pay');
    $bill_pay_obj->bill_no = $bill_no;
    $bill_pay_obj->payTypeID = 63;
    if (!$G_SHOP->DBCA->fetch($bill_pay_obj)) {
        $bill_pay_obj->payTypeName = '微支付';
        $bill_pay_obj->type = 2;
        $bill_pay_obj->pay_amount = $params['total_fee']/100;
        $G_SHOP->DBCA->save($bill_pay_obj);

    }

    $arg_array = array(
        'bill_no' => $bill_no,
        'pcustID' => $pcustID,
        'payTypeID' => $payTypeID,
        'billType' => 1,
        'total_amount' => $params['total_fee'],
        'pay_code' => $params['transaction_id']
    );
    $res = $ebsigOnlinepay->payAction( $arg_array );




            //加载短信类
            quanli_include('module/base/common/quanliSms.class.php');

            //实例化短信类
            $quanliSms = new quanliSms();
            //查询短信内容
            $billSql="select custID,bill_code,send_start_time,send_end_time,bill_totalAmount from bill_master where bill_no=?";
            $billQuest=$G_SHOP->DBCA->stmt_query($billSql,'s',$bill_no);
            /**
             * ============================
             * 发送短信
             * ============================
             */
            //生成短信内容
            $data_array = array(
                '$bill_code' => $billQuest[0]->bill_code,
                '$packageNum' =>$billQuest[0]->bill_totalAmount/2,
                '$send_time' =>$billQuest[0]->send_start_time."-".$billQuest[0]->send_end_time,
            );
            $sms_content = $quanliSms->getSmsContent( 'dunch_bill_pay', $data_array );

            //发送短信
            $result_array = $quanliSms->sendSMS(  $billQuest[0]->custID, $sms_content );

    $bill_master="update bill_master set bill_status=1,pay_type=2,payTypeID=63,payTypeName='微支付',payment_method_id=0 where billPlatform=3 and bill_no=? and (bill_status=0 or bill_status=10)";
    //$bill_master="update bill_master set pay_type=2,payTypeID=66,payTypeName='下午茶支付宝(wap)',payment_method_id=0, pay_status=1 where billPlatform=3 and bill_no=? and (bill_status=0 or bill_status=10)";
    $G_SHOP->DBCA->stmt_query($bill_master,'s',$bill_no);


    echo "success";
}

die( 'fail' );